﻿@model Zatify.WebUI.Models.BusinessProfilePromotionsViewModel
@{
    ViewBag.Title = "My Promotion";
    ViewBag.ContentTitle = "My Promotion";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}
@section Styles
{
    <style type="text/css">
        .inner_container
        {
            float: none;
        }
        .validation-summary-errors
        {
            margin-bottom: 15px;
        }
    </style>
}
@helper GetPromoTimeIntervalText(Zatify.Domain.Data.Promotion promo)
    {
        if (promo.BaseCostTimingId == Zatify.WebUI.Models.PromotionConstants.TIMING_BASE_COST || promo.BaseCostTimingId == Zatify.WebUI.Models.PromotionConstants.TIMING_INSTANT_NOW)
        {
            <text>
                @(promo.BaseCostTimingScheduledAt.HasValue ? promo.BaseCostTimingScheduledAt.Value.ToString("MM-dd-yyyy hh:mm tt") : "")
            </text>
        }
        else if (promo.BaseCostTimingId == Zatify.WebUI.Models.PromotionConstants.TIMING_SCHEDULED_AT)
        {
            <text>
                @(promo.BaseCostTimingStarts.HasValue ? promo.BaseCostTimingStarts.Value.ToString("MM-dd-yyyy hh:mm tt") : "")
            </text>
        }
        else if (promo.BaseCostTimingId == Zatify.WebUI.Models.PromotionConstants.TIMING_ONGOING_WITH_DATE_RANGE)
        {
            <text>
                @(promo.BaseCostTimingStarts.HasValue ? promo.BaseCostTimingStarts.Value.ToString("MM-dd-yyyy") : "")
                to
                @(promo.BaseCostTimingEnds.HasValue ? promo.BaseCostTimingEnds.Value.ToString("MM-dd-yyyy") : "");
                @(promo.BaseCostTimingStarts.HasValue ? promo.BaseCostTimingStarts.Value.ToString("hh:mm tt") : "")
                -
                @(promo.BaseCostTimingEnds.HasValue ? promo.BaseCostTimingEnds.Value.ToString("hh:mm tt") : "");
            </text>
        }
}
<div class="business_interface_area">
    <div class="business_profile_categories">
        @if (@TempData["Error"] != null)
        {
            <div class="validation-summary-errors">
                <ul>
                    <li>@TempData["Error"]</li></ul>
            </div>
        }
        @foreach (var promo in Model.Promotions)
        {
            if (promo.Status == Zatify.Domain.Data.PromotionStatus.Active)
            {
            <a href="@Url.Action("Details", "Promotions", new { id = promo.PromotionId })">
                <div class="my_prototion_line">
                    <div class="my_prototion prototion_active">
                        <div class="my_prototion_content">
                            @GetPromoTimeIntervalText(promo)
                            @promo.Name <span style="float: right;">@promo.SpentPushes</span></div>
                    </div>
                    <div class="right_info active_color">
                        <div class="my_prototion_content">
                            @promo.CheckinCode</div>
                    </div>
                </div>
            </a>
            }
            else if (promo.Status == Zatify.Domain.Data.PromotionStatus.Pending)
            {
            <a href="@Url.Action("Details", "Promotions", new { id = promo.PromotionId })">
                <div class="my_prototion_line">
                    <div class="my_prototion prototion_pending">
                        <div class="my_prototion_content">
                            @GetPromoTimeIntervalText(promo)
                            @promo.Name <span style="float: right;">@promo.SpentPushes</span></div>
                    </div>
                    <div class="right_info">
                        <a href="@Url.Action("DeletePromotion", "BusinessProfile", new { id = @promo.PromotionId })" onclick="return confirm('Delete selected promotoin?')">
                            <img class="promotion_control" src="@Url.Content("~/Content/zatify/images/minus_btn.png")" alt="" /></a>
                    </div>
                </div>
            </a>
            }
            else
            {
            <a href="@Url.Action("Details", "Promotions", new { id = promo.PromotionId })">
                <div class="my_prototion_line">
                    <div class="my_prototion prototion_finished">
                        <div class="my_prototion_content">
                            @GetPromoTimeIntervalText(promo)
                            @promo.Name <span style="float: right;">@promo.SpentPushes</span></div>
                    </div>
                    <div class="right_info">
                        <div class="my_prototion_content">
                            &nbsp;</div>
                    </div>
                </div>
            </a>
            }
        }
        <a href="@Url.Action("Add", "BusinessProfile")">
            <input type="button" value="Add New" class="blue_btn" style="margin-left: 0px;" />
        </a>
    </div>
    <div class="clearfix">
    </div>
</div>
